package com.yx.backstage.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author yangx
 */
@Configuration
public class KaptChaConfig {

    @Bean
    public Producer kaptchaProducer(){
        Properties properties=new Properties();
        //图片的宽度
        properties.setProperty("kaptcha.image.width","120");
        //去除边框
        properties.setProperty("kaptcha.border", "no");
        //图片的高度
        properties.setProperty("kaptcha.image.height","40");
        //字体大小
        properties.setProperty("kaptcha.textproducer.font.size","32");
        //字体颜色（RGB）
        properties.setProperty("kaptcha.textproducer.font.color","black");
        //验证码字符的集合
       properties.setProperty("kaptcha.textproducer.char.string","123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
        //验证码长度（即在上面集合中随机选取几位作为验证码）
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //图片的干扰样式
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        //干扰颜色
        properties.setProperty("kaptcha.noise.color", "white");
        //干扰样式
        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");

        DefaultKaptcha kaptCha = new DefaultKaptcha();
        Config config=new Config(properties);
        kaptCha.setConfig(config);
        return kaptCha;
    }
}